<template>
	<view class="register">
		<u-navbar height="100" bgColor="#F4F6F8" placeholder>
			<navigator class="u-nav-slot c-theme-btn-w" slot="left" url="../Login/Login">
				<image src="../../static/imgs/left.png"></image>
			</navigator>
		</u-navbar>
		<view class="register-title">
			账号注册
		</view>
		<u-form errorType="message" labelPosition="left" :model="loginForm" :borderBottom="false" :rules="formRules" ref="formRef">
			<u-form-item prop="username" style="box-shadow: ;">
				<u-input clearable border="false" shape="circle" v-model="loginForm.username" placeholder="请输入您的用户名">
				</u-input>
			</u-form-item>
			<u-form-item prop="password">
				<u-input type="password" clearable border="false" shape="circle" v-model="loginForm.password" placeholder="请输入登录密码">
				</u-input>
			</u-form-item>
			<u-form-item prop="password" >
				<u-input type="password" clearable border="false" shape="circle" v-model="loginForm.aginPassword" placeholder="确认密码">
				</u-input>
			</u-form-item>
		</u-form>
		<view class="register-deal">
			<u-radio-group v-model="value" iconPlacement="right">
				<u-radio></u-radio>
			</u-radio-group>
			<view class="deal-title">
				登陆注册即表示同意 <navigator url="">用户协议</navigator> 和 <navigator>隐私条款</navigator>
			</view>
		</view>
		<view class="register-btn c-theme-btn-b" @click="userRegister">
			注册
		</view>
	</view>
</template>

<script>
	import {
		register
	} from "@/api/login.js"
	import {
		TOAST
	} from "@/utils/utils.js"
	export default {
		data() {
			return {
				loginForm: {
					username:"",
					password:"",
					aginPassword:""
				},
				value: "",
				// 表单验证规则
				formRules: {
					username: [{
						required: true,
						message: '请输入用户名',
						trigger: ['blur', 'change']
					}],
					password: [{
						required: true,
						message: '请输入密码',
						trigger: ['blur', 'change']
					}],
					aginPassword: [{
						required: true,
						message: '请再次输入密码',
						trigger: ['blur', 'change']
					}]
				}
			};
		},
		methods:{
			userRegister(){
				this.$refs.formRef.validate().then(() => {
					register({
						username:this.loginForm.username,
						password:this.loginForm.password
					}).then(res=>{
						if(res.code===200){
							TOAST("注册成功")
							setTimeout(()=>{
								uni.navigateTo({
									url:"/pages/Login/Login"
								})
								this.$refs.formRef.resetFields()
							},1000)
						}
					}).catch(err=>{
						console.log(err)
					})
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	.u-radio-group {
		flex: 0;
	}

	.register {
		height: 100%;
		overflow-y: auto;
		padding: 0 104rpx;

		.u-nav-slot {
			width: 80rpx;
			background-color: #FFFFFF;
			border-radius: 50%;
			height: 80rpx;
			line-height: 90rpx;
			text-align: center;
			margin-left: 60rpx;

			image {
				width: 21rpx;
				height: 34rpx;
			}
		}

		.register-title {
			margin-top: 100rpx;
			font-weight: bold;
			color: #3F7BED;
			font-size: 52rpx;
		}

		.u-form {
			margin-top: 200rpx;
		}

		.register-deal {
			display: flex;
			margin-top: 8rpx;

			.deal-title {
				display: flex;
				align-items: center;
				color: #999FAD;

				navigator {
					color: #3F7BED;
				}
			}
		}

		.register-btn {
			margin-top: 80rpx;
			width: 100%;
			border: 1px solid #FFFFFF;
			border-radius: 40rpx 40rpx 40rpx 40rpx;
			background-color: #3F7BED;
			line-height: 100rpx;
			text-align: center;
			color: #FFFFFF;
		}
	}
</style>
